import type * as Store from './type'
import http from '@/utils/http'

const BASE_URL = '/system/category'


export interface CategoryPageQuery extends CategoryQuery, PageQuery {}

/** @desc 查询分类列表 */
export function listCategory(query: CategoryPageQuery) {
  return http.get<PageRes<Store.CategoryResp[]>>(`${BASE_URL}`, query)
}

/** @desc 分类数据tree数据 */
export function treeCategory(query) {
  const data = {
    type: query.type,
    status: query.status,
    name: query.name
  }
  return http.get<PageRes<Store.CategoryResp[]>>(`${BASE_URL}/list/tree`, data)
}

/** @desc 查询分类详情 */
export function getCategory(id: string) {
  return http.get<Store.CategoryDetailResp>(`${BASE_URL}/${id}/info`)
}

/** @desc 新增分类 */
export function addCategory(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改分类 */
export function updateCategory(data: any, id: string) {
  return http.patch(`${BASE_URL}/${id}/update`, data)
}

/** @desc 修改分类状态 */
export function updateCategoryStatus(id: string) {
  return http.patch(`${BASE_URL}/${id}/update/status`)
}

/** @desc 删除分类 */
export function deleteCategory(id: string) {
  return http.patch(`${BASE_URL}/${id}/delete`)
}

/** @desc 导出分类 */
export function exportCategory(query: CategoryQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}

